package com.atguigu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author 伟哥
 * @date 2021-04-29 10:55
 */
public class MyBeanPostProcessorImpl implements BeanPostProcessor {
    /**
     * 初始化之前调用
     * @param bean 将要初始化的bean
     * @param beanName bean在xml中配置的id
     * @return bean
     * @throws BeansException 跟随接口，抛出异常
     */
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization...将要初始化的bean的名字:"+beanName+"；对象是："+bean);

        //初始化之前返回的bean
        return bean;
    }

    /**
     * 初始化之后调用
     * @param bean 初始化后的bean
     * @param beanName bean在xml中配置的id
     * @return bean
     * @throws BeansException 跟随接口，抛出异常
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization...已经初始化完毕的bean的名字:"+beanName+"；对象是："+bean);

        /*
        初始化之后返回的bean
        ★★★这里返回的是什么，ioc容器中，保存的就是什么★★★
         */
        return bean;
    }
}
